﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.IO.Compression;

namespace BL
{
    public class Compress
    {
        public static string Deccompress(byte[] byteArray)
        {
            using (var decomStream = new MemoryStream(byteArray))
            {
                using (var hgs = new GZipStream(decomStream, CompressionMode.Decompress))
                {
                    using (var reader = new StreamReader(hgs))
                    {
                        return reader.ReadToEnd();
                    }
                }
            }
        }



        public static byte[] Compressor(string text)
        {
            var encoding = new UTF8Encoding();
            var data = encoding.GetBytes(text);

            // Compress 
            using (var cmpStream = new MemoryStream())
            {
                using (var hgs = new GZipStream(cmpStream, CompressionMode.Compress))
                {
                    hgs.Write(data, 0, data.Length);
                }
                return cmpStream.ToArray();
                
            }

        }

    }
}
